package com.ketangpai.admin.controller;

import com.ketangpai.admin.entity.GroupMember;
import com.ketangpai.admin.service.GroupMemberService;
import com.ketangpai.admin.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("group")
@Api(tags = "成员分组表")
public class GroupController {
    /**
     * 服务对象
     */
    @Resource
    private GroupMemberService service;

    /**
     * 查询所有数据
     */
    @ApiOperation("查询所有数据")
    @GetMapping("/selectAll")
    public JsonResult<?> selectAll(){
        List<GroupMember> list=service.getAll();
        return JsonResult.success(list);
    }

    /**
     * 新增数据
     */
    @ApiOperation("添加")
    @PostMapping("/insert")
    public JsonResult<?> insert(@RequestBody GroupMember groupMember){
        boolean result=  service.insert(groupMember);
        if (result) {
            return JsonResult.success("添加成功");
        }
        return JsonResult.error("添加失败");

    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    public JsonResult<?> delete(@PathVariable Integer id){
        boolean result=service.deleteById(id);
        if (result) {
            return JsonResult.success("删除成功");
        }
        return JsonResult.error("删除失败");
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public JsonResult<?> update(@RequestBody GroupMember groupMember){
        boolean result=service.update(groupMember);
        if (result) {
            return JsonResult.success("编辑成功");
        }
        return JsonResult.error("编辑失败");
    }

}
